//
//  YMHomeRecordListCell.m
//  YMMedical
//
//  Created by y s on 2023/7/19.
//

#import "YMHomeRecordListCell.h"

@interface YMHomeRecordListCell ()

@property (nonatomic, strong) UIView *vBg;
@property (nonatomic, strong) UILabel *lblName;
@property (nonatomic, strong) UILabel *lblTime;
@property (nonatomic, strong) UILabel *lblResult;
@property (nonatomic, strong) UILabel *lblNext;

@end

@implementation YMHomeRecordListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - UI methods
- (void)setUI{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    
    UILabel *lblProject = [SThemeUtil label:KLanguage(@"pdf_fix_txt") color:STheme.H_D1 fontSize:14];
    UILabel *lblDateL = [SThemeUtil label:KLanguage(@"date_fix_txt") color:STheme.H_D1 fontSize:14];
    UILabel *lblCheckL = [SThemeUtil label:KLanguage(@"dete_result_fix_txt") color:STheme.H_D1 fontSize:14];
    
    [self.contentView addSubview:self.vBg];
    [self.vBg addSubview:lblProject];
    [self.vBg addSubview:self.lblName];
    [self.vBg addSubview:lblDateL];
    [self.vBg addSubview:self.lblTime];
    [self.vBg addSubview:lblCheckL];
    [self.vBg addSubview:self.lblResult];
    [self.vBg addSubview:self.lblNext];
    
    [self.vBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo([SFitUtil fit:-10]);
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.top.mas_equalTo(0);
    }];
    [lblProject mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo([SFitUtil fit:15]);
        make.top.mas_equalTo([SFitUtil fit:15]);
    }];
    [self.lblName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lblProject.mas_right);
        make.centerY.equalTo(lblProject);
        make.right.lessThanOrEqualTo(lblDateL.mas_left).offset([SFitUtil fit:-5]);
    }];
    [self.lblTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.centerY.equalTo(lblProject);
    }];
    [lblDateL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.lblTime.mas_left);
        make.centerY.equalTo(lblProject);
    }];
    
    [lblProject setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
    [self.lblTime setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
    [lblDateL setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
    [self.lblName setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
    
    [lblCheckL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lblProject);
        make.top.equalTo(lblProject.mas_bottom).offset([SFitUtil fit:20]);
    }];
    [self.lblResult mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lblCheckL);
        make.left.equalTo(lblCheckL.mas_right);
        make.right.mas_lessThanOrEqualTo([SFitUtil fit:-15]);
    }];
    [lblCheckL setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
    [self.lblResult setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
    
    
    [self.lblNext mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lblProject);
        make.top.equalTo(self.lblResult.mas_bottom).offset([SFitUtil fit:20]);
        make.top.greaterThanOrEqualTo(lblCheckL.mas_bottom).offset([SFitUtil fit:19]);
        make.right.mas_equalTo([SFitUtil fit:-15]);
        make.bottom.mas_equalTo([SFitUtil fit:-15]);
    }];
}


#pragma mark - public methods
- (void)setDict:(NSDictionary *)dict{
    _dict = dict;
    
    self.lblResult.text = [SDataUtil stringOf:dict[@"primaryResDisplay"]];
    self.lblTime.text =  [SDataUtil stringOf:dict[@"collectDate"] valid:@""];
    self.lblName.text = [SDataUtil stringOf:dict[@"minorTermName"] valid:@""];
    self.lblNext.text = [NSString stringWithFormat:@"%@: %@",KLanguage(@"last_dete_time_txt"),[SDataUtil stringOf:dict[@"nextCollectDate"] valid:@""]];
}


#pragma mark - Event Action



#pragma mark - setter and getter
- (UIView *)vBg{
    if (_vBg == nil){
        _vBg = [[UIView alloc] init];
        _vBg.backgroundColor = STheme.D9;
        _vBg.layer.cornerRadius = [SFitUtil fit:8];
        _vBg.clipsToBounds = YES;
    }
    return _vBg;
}
- (UILabel *)lblName{
    if (_lblName == nil){
        _lblName = [[UILabel alloc] init];
        _lblName.textColor = STheme.D3;
        _lblName.font = [SFitUtil fitFont:14];
    }
    return _lblName;
}
- (UILabel *)lblTime{
    if (_lblTime == nil){
        _lblTime = [[UILabel alloc] init];
        _lblTime.textColor = STheme.D3;
        _lblTime.font = [SFitUtil fitFont:14];
    }
    return _lblTime;
}
- (UILabel *)lblResult{
    if (_lblResult == nil){
        _lblResult = [[UILabel alloc] init];
        _lblResult.textColor = STheme.D12;
        _lblResult.font = [SFitUtil fitFont:14];
        _lblResult.numberOfLines = 0;
    }
    return _lblResult;
}
- (UILabel *)lblNext{
    if (_lblNext == nil){
        _lblNext = [[UILabel alloc] init];
        _lblNext.textColor = STheme.D3;
        _lblNext.font = [SFitUtil fitFont:12];
    }
    return _lblNext;
}

@end
